# -*- coding: utf-8 -*-
from functools import reduce
def str2float(s):
	def char2num(c):
		digits = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}
		return digits[c]
	def fn(x, y):
		return x * 10 + y
	def gn(x, y):
		return x / 10 + y 

	s1, s2 = s.split('.')
# s1代表小数点前面的数字 s2取小数点后面的数字
	return reduce(fn, map(char2num,s1)) + reduce(gn, map(char2num,s2[::-1])) / 10

print('str2float(\'123.456\') =', str2float('123.456'))
if abs(str2float('123.456') - 123.456) < 0.00001:
    print('测试成功!')
else:
    print('测试失败!')